/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulemaker;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author takao
 */
public class ModuleMaker {

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) throws IOException, TemplateException {

    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File("src/modulemaker/templates"));
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    Template temp = cfg.getTemplate("add.ftl");

    Table clients = new Table("clients");
    clients.addColumn(new Column("client_id", Column.Type.PRIMARY_KEY));
    clients.addColumn(new Column("name", Column.Type.STRING, Column.Contraint.NOT_NULL));
    clients.addColumn(new Column("bday", Column.Type.DATE));
    clients.addColumn(new Column("address", Column.Type.STRING));
    clients.addColumn(new Column("cellPhone", Column.Type.STRING));
    clients.addColumn(new Column("workPhone", Column.Type.STRING));
    clients.addColumn(new Column("eMail", Column.Type.STRING));
    clients.addColumn(new Column("ec_Name", Column.Type.STRING));
    clients.addColumn(new Column("ec_Relationship", Column.Type.STRING));
    clients.addColumn(new Column("ec_CellPhone", Column.Type.STRING));
    clients.addColumn(new Column("ec_HomePhone", Column.Type.STRING));
    clients.addColumn(new Column("p_Name", Column.Type.STRING));
    clients.addColumn(new Column("p_Phone", Column.Type.STRING));
    clients.addColumn(new Column("p_Fax", Column.Type.STRING));
    clients.addColumn(new Column("referredBy", Column.Type.STRING));
    clients.addColumn(new Column("dateRegistered", Column.Type.DATE));
    clients.addColumn(new Column("status", Column.Type.BOOLEAN, Column.Contraint.DEFAULT.value("0")));
    Map root = new HashMap();
    root.put("clients", clients);


    /* Merge data-model with template */
    Writer out = new OutputStreamWriter(System.out);
    temp.process(root, out);
    out.flush();

  }
}
